﻿using UnityEngine;
using UnityEngine.UI;

public class UserBaseInfo : MonoBehaviour
{
    public Text nameText;
    public NetworkImage iconImg;
    public Text statusText;
    public Text birthYear;
    public Text location;
    public Text hometown;
    public Text height;
    public Text eduation;
    public Text job;
    public Image verifyBg;
    public Text verifyText;

    public Color bgActiveColor = Color.white;
    public Color bgDisactiveColor = Color.white;

    public void Init(UserInfo userInfo)
    {
        //int width = userInfo.icon.texWidth;
        //int hei = userInfo.icon.texHeight;
        iconImg.Init(userInfo.icon);
        nameText.text = userInfo.name;
        birthYear.text = userInfo.birthYear % 1900 + "年";
        location.text = "现居" + userInfo.locationProvince+ userInfo.locationCity;
        hometown.text = userInfo.hometownCity;
        height.text = userInfo.height + "cm";
        eduation.text = DataString.GetEducationString(userInfo.eduation);
        job.text = userInfo.job;
        if(statusText)
            statusText.text = userInfo.status;

        if (verifyText && verifyBg)
        {
            if (userInfo.realNameVerify)
            {
                verifyBg.color = bgActiveColor;
                verifyText.text = "已认证";
            }
            else
            {
                verifyBg.color = bgDisactiveColor;
                verifyText.text = "未认证";
            }
        }

        //if(gameObject.activeInHierarchy)
        //    StartCoroutine(UnityFunctions.AdjustItemsLayout(transform));
    }

    void OnEnable()
    {
        StartCoroutine(UnityFunctions.AdjustItemsLayout(transform));
    }

    //void OnDestroy()
    //{
    //    bool exist = NewTextureController.instance.OnDestroySpr(iconImg.sprite);
    //    if (!exist)
    //    {
    //        //Destroy(iconImg.sprite);
    //    }
    //}
}
